// // --------------------------------------------------------------------------------------------------------------------
// // <copyright file="GlobalSettingsForm.cs" company="Collaboris">
// //   Copyright Collaboris
// // </copyright>
// // <summary>
// //   
// // </summary>
// // --------------------------------------------------------------------------------------------------------------------

namespace DocRead.Selenium.Tests.DocRead.ControlObjects
{
    #region

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    using Collaboris.ShareTest.Core;
    using Collaboris.ShareTest.SharePoint2010.ControlObjects;

    using OpenQA.Selenium;
    using OpenQA.Selenium.Remote;
    using OpenQA.Selenium.Support.UI;

    using global::DocRead.Selenium.Tests.DocRead.PageObjects.CA;

    #endregion

    public class GlobalSettingsForm : SPTModelBase
    {
        #region Constants and Fields

        public static string AudSyncJobDailyElementId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobRadioButtonList_0";

        public static string AudSyncJobHourlyElementId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobRadioButtonList_1";

        public static string AudSyncJobRunNowElementId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobRadioButtonList_2";

        public static string CtrlAudSyncIntervalDailyEndHourId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobEndHourTextBox";

        public static string CtrlAudSyncIntervalDailyStartHourId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobStartHourTextBox";

        public static string CtrlAudiencesSyncJobId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobRadioButtonList";

        public static string CtrlAudiencesSyncJobIntevalHourlyId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobHoursIntervalTextBox";

        public static string CtrlCancelButton = "ctl00_PlaceHolderMain_ctl00_BtnCancel";

        public static string CtrlControlsSkinId = "ctl00_PlaceHolderMain_SkinsSection_ddWidgetSkin";

        public static string CtrlDefaultRecommendedDaysId =
            "ctl00_PlaceHolderMain_DefaultValuesSection_RecommendedReadershipDefaultValueTextBox";

        public static string CtrlDefaultRequiredDaysId =
            "ctl00_PlaceHolderMain_DefaultValuesSection_RequiredReadershipDefaultValueTextBox";

        public static string CtrlErrorAudiencesJobHourlyId =
            "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobHourlyScheduleValidator";

        public static string CtrlErrorDefaultRecommendedDaysId =
            "ctl00_PlaceHolderMain_DefaultValuesSection_RecommendedReadershipValidator";

        public static string CtrlErrorDefaultRequiredDaysId =
            "ctl00_PlaceHolderMain_DefaultValuesSection_RequiredReadershipValidator";

        public static string CtrlErrorMaxNumberThreadsId =
            "ctl00_PlaceHolderMain_ProcessingThreadsSection_ProcessingThreadsValidator";

        public static string CtrlErrorReadershipProcessingJobHourlyId =
            "ctl00_PlaceHolderMain_JobScheduleSection_HourlyScheduleValidator";

        public static string CtrlErrorSharePointObjectsJobHourlyId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobHourlyScheduleValidator";

        public static string CtrlMaxNumberThreadsId =
            "ctl00_PlaceHolderMain_ProcessingThreadsSection_ProcessingThreadsTextBox";

        public static string CtrlOkButton = "ctl00_PlaceHolderMain_ctl00_RptControls_SetOptionsButton";

        public static string CtrlReadProcIntervalDailyEndHourId =
            "ctl00_PlaceHolderMain_JobScheduleSection_EndHourTextBox";

        public static string CtrlReadProcIntervalDailyStartHourId =
            "ctl00_PlaceHolderMain_JobScheduleSection_StartHourTextBox";

        public static string CtrlReadProcessingJobDailyElementId =
            "ctl00_PlaceHolderMain_JobScheduleSection_ScheduleRadioButtonList_0";

        public static string CtrlReadProcessingJobHourlyElementId =
            "ctl00_PlaceHolderMain_JobScheduleSection_ScheduleRadioButtonList_1";

        public static string CtrlReadProcessingJobRunNowElementId =
            "ctl00_PlaceHolderMain_JobScheduleSection_ScheduleRadioButtonList_2";

        public static string CtrlReadershipProcessingJobIntervalHourlyId =
            "ctl00_PlaceHolderMain_JobScheduleSection_HoursIntervalTextBox";

        public static string CtrlReadershipProcessingJobName =
            "ctl00$PlaceHolderMain$JobScheduleSection$ScheduleRadioButtonList";

        public static string CtrlSelectedWebAppsClass = "selectlist-list";

        public static string CtrlSharePointObjectsIntervalDailyEndHourId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobEndHourTextBox";

        public static string CtrlSharePointObjectsIntervalDailyStartHourId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobStartHourTextBox";

        public static string CtrlSharePointObjectsJobDailyElementId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobRadioButtonList_0";

        public static string CtrlSharePointObjectsJobHourlyElementId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobRadioButtonList_1";

        public static string CtrlSharePointObjectsJobRunNowElementId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobRadioButtonList_2";

        public static string CtrlSharePointObjectsSyncJobId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobRadioButtonList";

        public static string CtrlSharePointObjectsSyncJobIntervalHourlyId =
            "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobHoursIntervalTextBox";

        public static string CtrlSkinOverrideId = "ctl00_PlaceHolderMain_SkinsSection_ddReadershipSkin";

        public static string CtrlWebApplicationSelectClass = "clbApplicationSelector";

        public static string CtrlErrorReadershipProcessingJobDailyId = "ctl00_PlaceHolderMain_JobScheduleSection_DailyScheduleValidator";
        public static string CtrlErrorReadershipProcessingJobStartDailyId = "ctl00_PlaceHolderMain_JobScheduleSection_DailyScheduleValidator1";
        public static string CtrlErrorReadershipProcessingJobEndDailyId = "ctl00_PlaceHolderMain_JobScheduleSection_DailyScheduleValidator2";

        public static string CtrlErrorAudiencesSyncJobDailyId = "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobDailyScheduleValidator";
        public static string CtrlErrorAudiencesSyncJobDailyStartId = "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobDailyScheduleValidator1";
        public static string CtrlErrorAudiencesSyncJobDailyEndId = "ctl00_PlaceHolderMain_AudienceJobScheduleSection_AudienceJobDailyScheduleValidator2";

        public static string CtrlErrorSharePointObjectsSyncJobDailyId = "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobDailyScheduleValidator";
        public static string CtrlErrorSharePointObjectsSyncJobDailyStartId = "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobDailyScheduleValidator1";
        public static string CtrlErrorSharePointObjectsSyncJobDailyEndId = "ctl00_PlaceHolderMain_SharePointSyncJobScheduleSection_SharePointSyncJobDailyScheduleValidator2";

        private List<string> webApplications;

        #endregion

        #region Constructors and Destructors

        public GlobalSettingsForm(RemoteWebDriver driver)
            : base(driver)
        {
        }

        #endregion

        #region Public Properties

        public IWebElement AudSyncJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(AudSyncJobDailyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(AudSyncJobDailyElementId));
                }
                return null;
            }
        }

        public IWebElement AudSyncJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(AudSyncJobHourlyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(AudSyncJobHourlyElementId));
                }
                return null;
            }
        }

        public IWebElement AudSyncJobRunNowElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(AudSyncJobRunNowElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(AudSyncJobRunNowElementId));
                }
                return null;
            }
        }

        public string AudiencesInterval { get; set; }

        /// <summary>
        /// 	AudiencesSync frequency
        /// </summary>
        public IWebElement AudiencesSyncJobElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlAudiencesSyncJobId);
            }
        }

        public Frequency AudiencesJobFreq { get; set; }

        public IWebElement AudiencesSyncJobIntervalDailyEndElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlAudSyncIntervalDailyEndHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlAudSyncIntervalDailyEndHourId);
                }
                return null;
            }
        }

        public IWebElement AudiencesSyncJobIntervalDailyStartElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlAudSyncIntervalDailyStartHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlAudSyncIntervalDailyStartHourId);
                }
                return null;
            }
        }

        /// <summary>
        /// 	AudiencesSyncg Every...
        /// </summary>
        public IWebElement AudiencesSyncJobIntervalHourlyElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlAudiencesSyncJobIntevalHourlyId);
            }
        }

        public IWebElement CancelButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlCancelButton);
            }
        }

        public string ControlsSkin { get; set; }

        /// <summary>
        /// 	ControlsSkinElement Every...
        /// </summary>
        public IWebElement ControlsSkinElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlControlsSkinId);
            }
        }

        /// <summary>
        /// 	List of Web Apps Element
        /// </summary>
        public IWebElement SelectedWebAppsElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.ClassName(CtrlSelectedWebAppsClass)))
                {
                    return this.WebDriver.FindElementByClassName(CtrlSelectedWebAppsClass);
                }
                return null;
            }
        }

        public string DefaultRecommendedDays { get; set; }

        /// <summary>
        /// 	DefaultRequiredDaysId Every...
        /// </summary>
        public IWebElement DefaultRecommendedDaysElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlDefaultRecommendedDaysId);
            }
        }

        public string DefaultRequiredDays { get; set; }

        /// <summary>
        /// 	DefaultRequiredDaysId Every...
        /// </summary>
        public IWebElement DefaultRequiredDaysElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlDefaultRequiredDaysId);
            }
        }

        public string ErrorAudiencesJobHourly { get; set; }

        public IWebElement ErrorAudiencesJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorAudiencesJobHourlyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorAudiencesJobHourlyId);
                }
                return null;
            }
        }

        public string ErrorAudiencesJobDailyStart { get; set; }

        public IWebElement ErrorAudiencesJobDailyStartElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorAudiencesSyncJobDailyStartId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorAudiencesSyncJobDailyStartId);
                }
                return null;
            }
        }

        public string ErrorAudiencesJobDailyEnd { get; set; }

        public IWebElement ErrorAudiencesJobDailyEndElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorAudiencesSyncJobDailyEndId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorAudiencesSyncJobDailyEndId);
                }
                return null;
            }
        }

        public string ErrorAudiencesJobDaily { get; set; }

        public IWebElement ErrorAudiencesJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorAudiencesSyncJobDailyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorAudiencesSyncJobDailyId);
                }
                return null;
            }
        }

        public string ErrorDefaultRecommendedDays { get; set; }

        public IWebElement ErrorDefaultRecommendedDaysElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorDefaultRecommendedDaysId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorDefaultRecommendedDaysId);
                }
                return null;
            }
        }

        public string ErrorDefaultRequiredDays { get; set; }

        public IWebElement ErrorDefaultRequiredDaysElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorDefaultRequiredDaysId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorDefaultRequiredDaysId);
                }
                return null;
            }
        }

        public string ErrorMaxNumberThreads { get; set; }

        public IWebElement ErrorMaxNumberThreadsElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorMaxNumberThreadsId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorMaxNumberThreadsId);
                }
                return null;
            }
        }

        public string ErrorReadershipJobHourly { get; set; }

        public IWebElement ErrorReadershipJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorReadershipProcessingJobHourlyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorReadershipProcessingJobHourlyId);
                }
                return null;
            }
        }

        public string ErrorReadershipJobDaily { get; set; }

        public IWebElement ErrorReadershipJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorReadershipProcessingJobDailyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorReadershipProcessingJobDailyId);
                }
                return null;
            }
        }

        public string ErrorReadershipJobStartDaily { get; set; }

        public IWebElement ErrorReadershipJobStartDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorReadershipProcessingJobStartDailyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorReadershipProcessingJobStartDailyId);
                }
                return null;
            }
        }

        public string ErrorReadershipJobEndDaily { get; set; }

        public IWebElement ErrorReadershipJobEndDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorReadershipProcessingJobEndDailyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorReadershipProcessingJobEndDailyId);
                }
                return null;
            }
        }

        public string ErrorSharePointJobHourly { get; set; }

        public IWebElement ErrorSharePointJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorSharePointObjectsJobHourlyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorSharePointObjectsJobHourlyId);
                }

                return null;
            }
        }

        public string ErrorSharePointJobStartDaily { get; set; }

        public IWebElement ErrorSharePointJobDailyStartElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorSharePointObjectsSyncJobDailyStartId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorSharePointObjectsSyncJobDailyStartId);
                }
                return null;
            }
        }

        public string ErrorSharePointJobDaily { get; set; }

        public IWebElement ErrorSharePointJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorSharePointObjectsSyncJobDailyId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorSharePointObjectsSyncJobDailyId);
                }
                return null;
            }
        }

        public string ErrorSharePointJobEndDaily { get; set; }

        public IWebElement ErrorSharePointJobDailyEndElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlErrorSharePointObjectsSyncJobDailyEndId)))
                {
                    return this.WebDriver.FindElementById(CtrlErrorSharePointObjectsSyncJobDailyEndId);
                }
                return null;
            }
        }

        public string MaxNumberThreads { get; set; }

        public IWebElement MaxNumberThreadsElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlMaxNumberThreadsId);
            }
        }

        public IWebElement OkButton
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlOkButton);
            }
        }

        public IWebElement ReadProcJobIntervalDailyEndElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlReadProcIntervalDailyEndHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlReadProcIntervalDailyEndHourId);
                }
                return null;
            }
        }

        public IWebElement ReadProcJobIntervalDailyStartElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlReadProcIntervalDailyStartHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlReadProcIntervalDailyStartHourId);
                }
                return null;
            }
        }

        public IWebElement ReadProcessingJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlReadProcessingJobDailyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlReadProcessingJobDailyElementId));
                }
                return null;
            }
        }

        public IWebElement ReadProcessingJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlReadProcessingJobHourlyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlReadProcessingJobHourlyElementId));
                }
                return null;
            }
        }

        public IWebElement ReadProcessingJobRunNowElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlReadProcessingJobRunNowElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlReadProcessingJobRunNowElementId));
                }
                return null;
            }
        }

        public string ReadershipInterval { get; set; }

        /// <summary>
        /// 	Readership processing frequency
        /// </summary>
        public IWebElement ReadershipProcessingJobElement
        {
            get
            {
                return this.WebDriver.FindElementByName(CtrlReadershipProcessingJobName);
            }
        }

        public Frequency ReadershipJobFreq { get; set; }

        /// <summary>
        /// 	Readership Processing Every...
        /// </summary>
        public IWebElement ReadershipProcessingJobIntervalHourlyElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlReadershipProcessingJobIntervalHourlyId);
            }
        }

        public string SharePointInterval { get; set; }

        /// <summary>
        /// 	SharePointObjects Every...
        /// </summary>
        public IWebElement SharePointObjectsIntervalHourlyElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlSharePointObjectsSyncJobIntervalHourlyId);
            }
        }

        public IWebElement SharePointObjectsJobDailyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlSharePointObjectsJobDailyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlSharePointObjectsJobDailyElementId));
                }
                return null;
            }
        }

        /// <summary>
        /// 	SharePointObjects frequency
        /// </summary>
        public IWebElement SharePointObjectsJobElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlSharePointObjectsSyncJobId);
            }
        }

        public Frequency SharePointJobFreq { get; set; }

        public IWebElement SharePointObjectsJobHourlyElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlSharePointObjectsJobHourlyElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlSharePointObjectsJobHourlyElementId));
                }
                return null;
            }
        }

        public IWebElement SharePointObjectsJobIntervalDailyEndElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlSharePointObjectsIntervalDailyEndHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlSharePointObjectsIntervalDailyEndHourId);
                }
                return null;
            }
        }

        public IWebElement SharePointObjectsJobIntervalDailyStartElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlSharePointObjectsIntervalDailyStartHourId)))
                {
                    return this.WebDriver.FindElementById(CtrlSharePointObjectsIntervalDailyStartHourId);
                }
                return null;
            }
        }

        public IWebElement SharePointObjectsJobRunNowElement
        {
            get
            {
                if (this.WebDriver.IsElementPresent(By.Id(CtrlSharePointObjectsJobRunNowElementId)))
                {
                    return this.WebDriver.FindElement(By.Id(CtrlSharePointObjectsJobRunNowElementId));
                }
                return null;
            }
        }

        /// <summary>
        /// 	SkinOverrideElement Every...
        /// </summary>
        public IWebElement SkinOverrideElement
        {
            get
            {
                return this.WebDriver.FindElementById(CtrlSkinOverrideId);
            }
        }

        public string SkingOverride { get; set; }

        public string TopLevelError { get; set; }

        public IWebElement TopLevelErrorElement
        {
            get
            {
                return this.WebDriver.IsElementPresent(By.XPath(Locators.XpathTopLevelErrorIdentifier))
                           ? this.WebDriver.FindElementByXPath(Locators.XpathTopLevelErrorIdentifier)
                           : null;
            }
        }

        /// <summary>
        /// 	WebApplication Element
        /// </summary>
        public IWebElement WebApplicationSelectElement
        {
            get
            {
                ReadOnlyCollection<IWebElement> allSelects = this.WebDriver.FindElementsByTagName("select");
                foreach (IWebElement webElement in allSelects)
                {
                    if (webElement.Displayed)
                    {
                        if (webElement.GetAttribute("class") == "clbApplicationSelector selectlist-select")
                        {
                            return webElement;
                        }
                    }
                }
                //if (this.WebDriver.FindElementsByTagName("select")))
                //{
                //    return this.WebDriver.FindElementByXPath("//select[@title='Select Web Application']");
                //}
                return null;
            }
        }

        public List<string> WebApplications 
        { 
            get
            {
                return this.webApplications ?? (this.webApplications = new List<string>());
            }
            set
            {
                webApplications = value;
            } 
        }

        #endregion

        #region Public Methods

        public void RefreshForm()
        {
            // titles
            // this.LicenseKey = this.WebApplicationSelectElement.GetAttribute("value");
            this.ReadershipJobFreq = this.GetReadProcessingFrequency();
            this.ReadershipInterval = this.ReadershipProcessingJobIntervalHourlyElement.GetAttribute("value");
            this.AudiencesJobFreq = this.GetAudProcessingFrequency();
            this.AudiencesInterval = this.AudiencesSyncJobIntervalHourlyElement.GetAttribute("value");
            this.SharePointJobFreq = this.GetSharePointObjectsFrequency();
            this.SharePointInterval = this.SharePointObjectsIntervalHourlyElement.GetAttribute("value");
            this.DefaultRequiredDays = this.DefaultRequiredDaysElement.GetAttribute("value");
            this.DefaultRecommendedDays = this.DefaultRecommendedDaysElement.GetAttribute("value");
            this.MaxNumberThreads = this.MaxNumberThreadsElement.GetAttribute("value");
            this.ControlsSkin = this.ControlsSkinElement.GetAttribute("value");
            this.SkingOverride = this.SkinOverrideElement.GetAttribute("value");
            
            WebApplications.Clear();

            if (this.SelectedWebAppsElement != null)
            {
                if (this.SelectedWebAppsElement.IsElementPresent(this.WebDriver, By.TagName("LI")))
                {
                    ReadOnlyCollection<IWebElement> listItems =
                        this.SelectedWebAppsElement.FindElements(By.TagName("LI"));
                    foreach (IWebElement listItem in listItems)
                    {
                        string fullText = listItem.Text.Replace("\r\n", "|");
                        string urlPart = fullText.Split(Convert.ToChar("|"))[1];

                        WebApplications.Add(urlPart);
                    }
                }
            }

            // errors
            if (this.TopLevelErrorElement != null)
            {
                this.TopLevelError = this.TopLevelErrorElement.Text;
            }

            if (this.ErrorReadershipJobHourlyElement != null)
            {
                this.ErrorReadershipJobHourly = this.ErrorReadershipJobHourlyElement.Text;
            }

            if (this.ErrorAudiencesJobHourlyElement != null)
            {
                this.ErrorAudiencesJobHourly = this.ErrorAudiencesJobHourlyElement.Text;
            }

            if (this.ErrorSharePointJobHourlyElement != null)
            {
                this.ErrorSharePointJobHourly = this.ErrorSharePointJobHourlyElement.Text;
            }

            if (this.ErrorReadershipJobDailyElement != null)
            {
                this.ErrorReadershipJobDaily = this.ErrorReadershipJobDailyElement.Text;
            }

            if (this.ErrorAudiencesJobDailyElement != null)
            {
                this.ErrorAudiencesJobDaily = this.ErrorAudiencesJobDailyElement.Text;
            }

            if (this.ErrorSharePointJobDailyElement != null)
            {
                this.ErrorSharePointJobDaily = this.ErrorSharePointJobDailyElement.Text;
            }

            if (this.ErrorReadershipJobStartDailyElement != null)
            {
                this.ErrorReadershipJobStartDaily = this.ErrorReadershipJobStartDailyElement.Text;
            }

            if (this.ErrorAudiencesJobDailyStartElement != null)
            {
                this.ErrorAudiencesJobDailyStart = this.ErrorAudiencesJobDailyStartElement.Text;
            }

            if (this.ErrorSharePointJobDailyStartElement != null)
            {
                this.ErrorSharePointJobStartDaily = this.ErrorSharePointJobDailyStartElement.Text;
            }

            if (this.ErrorReadershipJobEndDailyElement != null)
            {
                this.ErrorReadershipJobEndDaily = this.ErrorReadershipJobEndDailyElement.Text;
            }

            if (this.ErrorAudiencesJobDailyEndElement != null)
            {
                this.ErrorAudiencesJobDailyEnd = this.ErrorAudiencesJobDailyEndElement.Text;
            }

            if (this.ErrorSharePointJobDailyEndElement != null)
            {
                this.ErrorSharePointJobEndDaily = this.ErrorSharePointJobDailyEndElement.Text;
            }

            if (this.ErrorDefaultRequiredDaysElement != null)
            {
                this.ErrorDefaultRequiredDays = this.ErrorDefaultRequiredDaysElement.Text;
            }

            if (this.ErrorDefaultRecommendedDaysElement != null)
            {
                this.ErrorDefaultRecommendedDays = this.ErrorDefaultRecommendedDaysElement.Text;
            }

            if (this.ErrorMaxNumberThreadsElement != null)
            {
                this.ErrorMaxNumberThreads = this.ErrorMaxNumberThreadsElement.Text;
            }
        }

        public void SelectAudProcessingFrequency(Frequency frequency, string interval)
        {
            switch (frequency)
            {
                case Frequency.RunNowOnly:
                    {
                        this.AudSyncJobRunNowElement.Click();
                    }
                    break;
                case Frequency.Hourly:
                    {
                        this.AudSyncJobHourlyElement.Click();
                        if (interval.Contains("|"))
                        {
                            throw new ArgumentException("Hourly Scheduled only requires one value");
                        }
                        this.WebDriver.SendKeysAndClearIfDiff(this.AudiencesSyncJobIntervalHourlyElement, interval);
                    }
                    break;
                default:
                    {
                        this.AudSyncJobDailyElement.Click();

                        if (interval.Contains("|"))
                        {
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.AudiencesSyncJobIntervalDailyStartElement, interval.Split(Convert.ToChar("|"))[0]);
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.AudiencesSyncJobIntervalDailyEndElement, interval.Split(Convert.ToChar("|"))[1]);
                        }
                    }

                    break;
            }
        }

        public void SelectReadProcessingFrequency(Frequency frequency, string interval)
        {
            switch (frequency)
            {
                case Frequency.RunNowOnly:
                    {
                        this.ReadProcessingJobRunNowElement.Click();
                    }
                    break;
                case Frequency.Hourly:
                    {
                        this.ReadProcessingJobHourlyElement.Click();
                        if (interval.Contains("|"))
                        {
                            throw new ArgumentException("Hourly Scheduled only requires one value");
                        }

                        this.WebDriver.SendKeysAndClearIfDiff(
                            this.ReadershipProcessingJobIntervalHourlyElement, interval);
                    }
                    break;
                default:
                    {
                        this.ReadProcessingJobDailyElement.Click();
                        if (interval.Contains("|"))
                        {
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.ReadProcJobIntervalDailyStartElement, interval.Split(Convert.ToChar("|"))[0]);
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.ReadProcJobIntervalDailyEndElement, interval.Split(Convert.ToChar("|"))[1]);
                        }
                    }

                    break;
            }
        }

        public void SelectSpObjectsProcessingFrequency(Frequency frequency, string interval)
        {
            switch (frequency)
            {
                case Frequency.RunNowOnly:
                    {
                        this.SharePointObjectsJobRunNowElement.Click();
                    }
                    break;
                case Frequency.Hourly:
                    {
                        this.SharePointObjectsJobHourlyElement.Click();
                        if (interval.Contains("|"))
                        {
                            throw new ArgumentException("Hourly Scheduled only requires one value");
                        }
                        this.WebDriver.SendKeysAndClearIfDiff(this.SharePointObjectsIntervalHourlyElement, interval);
                    }
                    break;
                default:
                    {
                        this.SharePointObjectsJobDailyElement.Click();
                        if (interval.Contains("|"))
                        {
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.SharePointObjectsJobIntervalDailyStartElement,
                                interval.Split(Convert.ToChar("|"))[0]);
                            this.WebDriver.SendKeysAndClearIfDiff(
                                this.SharePointObjectsJobIntervalDailyEndElement, interval.Split(Convert.ToChar("|"))[1]);
                        }
                    }

                    break;
            }
        }

        #endregion

        #region Methods

        private Frequency GetAudProcessingFrequency()
        {
            if (this.AudSyncJobRunNowElement != null && this.AudSyncJobRunNowElement.Selected)
            {
                return Frequency.RunNowOnly;
            }
            if (this.AudSyncJobHourlyElement != null && this.AudSyncJobHourlyElement.Selected)
            {
                return Frequency.Hourly;
            }
            if (this.AudSyncJobDailyElement != null && this.AudSyncJobDailyElement.Selected)
            {
                return Frequency.Daily;
            }

            return Frequency.Daily; //
        }

        private Frequency GetReadProcessingFrequency()
        {
            if (this.ReadProcessingJobRunNowElement != null && this.ReadProcessingJobRunNowElement.Selected)
            {
                return Frequency.RunNowOnly;
            }
            if (this.ReadProcessingJobHourlyElement != null && this.ReadProcessingJobHourlyElement.Selected)
            {
                return Frequency.Hourly;
            }
            if (this.ReadProcessingJobDailyElement != null && this.ReadProcessingJobDailyElement.Selected)
            {
                return Frequency.Daily;
            }

            return Frequency.Daily; //
        }

        private Frequency GetSharePointObjectsFrequency()
        {
            if (this.SharePointObjectsJobRunNowElement != null && this.SharePointObjectsJobRunNowElement.Selected)
            {
                return Frequency.RunNowOnly;
            }
            if (this.SharePointObjectsJobHourlyElement != null && this.SharePointObjectsJobHourlyElement.Selected)
            {
                return Frequency.Hourly;
            }
            if (this.SharePointObjectsJobDailyElement != null && this.SharePointObjectsJobDailyElement.Selected)
            {
                return Frequency.Daily;
            }

            return Frequency.Daily; //
        }

        #endregion
    }
}